package com.collectplus.express.menu;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.collectplus.express.BaseActivity2;
import com.collectplus.express.R;

/**
 * 个人中心
 *
 * @author HuXinDan<br>
 *         2016-11-3上午10:18:33
 */
public class PersonalCenterActivity extends BaseActivity2 implements OnClickListener {

    private TextView mNickname;
    private LinearLayout mQrcode;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void findViewById() {
        setContentView(R.layout.personal_center);
        super.findViewById();
        getAppTitle().setCommonTitle("个人中心");
        mNickname = (TextView) findViewById(R.id.personal_nickname);
        mQrcode = (LinearLayout) findViewById(R.id.qrcode_center_layout);

        String name = getIntent().getStringExtra("name");
        mNickname.setText(name);

        mNickname.setOnClickListener(this);
        mQrcode.setOnClickListener(this);
        findViewById(R.id.personal_center_layout).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent intent = null;
        switch (v.getId()) {
            case R.id.personal_center_layout:
            case R.id.personal_nickname:
                intent = new Intent(getContext(), EditNameActivity.class);
                startActivityForResult(intent, 101);
                break;
            case R.id.qrcode_center_layout:
                intent = new Intent(getContext(), MyQRCodeActivity.class);
                startActivity(intent);
                break;
            default:
                break;
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == 101 && resultCode == RESULT_OK) {
            // 接收数据
            String nickname = data.getStringExtra("nickname");
            mNickname.setText(nickname);
        } else {
            super.onActivityResult(requestCode, resultCode, data);
        }
    }
}
